﻿traincurriculumlistmodule.controller('trainstatisModal', ['$scope', '$rootScope', 'trainStatisFactory', 'Msg', 'updateUrl', '$location', '$state', 'RequestPopService','MsgCon', 'sysUserInfo', 'RequestTrainService', '$state','FileUploader',  function ($scope, $rootScope, trainStatisFactory, Msg, updateUrl, $location, $state, RS, MsgCon, sysUserInfo, RTS, $state,FileUploader) {

    // 关闭用户编辑、新增页面
    $scope.closeuser = function () { $scope.title = ""; trainStatisFactory.deactivate(); updateUrl.upUrl(-1); }


    //上传文件对象
    $scope.uploader = new FileUploader();

    //预览地址
    $scope.cousrStatsUrl = $rootScope.coursurl;
    $scope.traininfo = []; //查询课程的相关信息
    $scope.detailedJSON = []; //课程章节
    $scope.ppLearn = []; //人员学习记录
    $scope.numCount = 0; //人员学习总记录数
    $scope.token = sysUserInfo.getuserinfotoken();
    $scope.PersList = { "examlist": [], "offlinelist": [], "multifilelist": [] }; //人员列表集合
    $scope.chapterJson = "";
    // 预览
    $scope.openKe = function () {
        var url = $rootScope.upurl + '/dispatcher/redirect?url=' + encodeURI(encodeURI($rootScope.fileurl + "/resources/template/" + $scope.traininfo.course_Id + ".html&token=" + $scope.token));
        window.open(url);
    }

    var reDateTime = /^(?:19|20)[0-9][0-9]-(?:(?:0[1-9])|(?:1[0-2]))-(?:(?:[0-2][1-9])|(?:[1-3][0-1])) (?:(?:[0-2][0-3])|(?:[0-1][0-9])):[0-5][0-9]:[0-5][0-9]$/;
    //失焦保存
    $scope.blurSave=function(obj){
        var time=obj.eDate;
        if(time==obj.date_time){
            return;
        }
        console.log("不一样")
        if(reDateTime.test(time)){

            RTS.modifyUserStudy({xid:obj.id,xtype:1,startTime:'',endTime:time,uid:sysUserInfo.getuserinfo().user_ID}).then(function(data){                          
                if (data.errorcode == "0") {
                    Msg.success("修改成功")
                    obj.date_time=time;
                }else if (data.errorcode != "6") {
                    Msg.error(data.errormsg);
                } else {
                    Msg.error("修改失败 ！");
                }                                  
            }, function callback() {                     
                Msg.error("修改异常！");
            });  
        }else{
            Msg.warning("请输入合法的日期！");
        }
    }
    //查询课程的相关信息
    $scope.courseRelevant = function () {
        RTS.courseRelevant({ courseid: $scope.courseid }).then(function (data) {
            if (data.errorcode == "0") {
                $scope.traininfo = data.datas[0];
            } else {
                console.log("查询课程的相关信息:" + data.errorcode);
            }
        });
    }
    $scope.isNull = function (val) {
        if (val == undefined || val == null || val == '') {
            return true;
        }
        return false;
    }
    //30天内课程观看人数的统计
    $scope.courseStatistics = function () {
        $scope.operateLoading = true;   // 开启loading       
        //   $scope.courseid      "76e18612-77ec-4d3d-a69b-5d95c1b13fa8"
        RTS.courseStatistics({ courseid: $scope.courseid, startDate: $scope.getdate(-30), endDate: $scope.getdate(1) }).then(function (response) {
            //            console.log(response);
            $scope.operateLoading = false;  //关闭loading            
            if (response.errorcode == "0") {// 成功       
                $scope.topOrg = response.datas;
                //,{"userId":"3","dateLearn":"2017-07-23 00:00:00"},{"userId":"3","dateLearn":"2017-07-24 00:00:00"}]}
                var dom = document.getElementById("container");
                var myChart = echarts.init(dom);
                var app = {};
                option = null;
                var newName = [];
                // 用户数量
                var newData = [];
                // 完成人数
                var newUserData = [];
                // 收藏量
                var newCollData = [];
                var newjson = response.datas; // eval(json2);

                newjson.forEach(function (val, index, arr) {
                    var yyyy = val.time.split(' ')[0].split('-')[0];
                    newName.push(val.time.split(' ')[0].replace(yyyy + "-", ""));
                    newData.push($scope.isNull(val.watch) ? 0 : val.watch);    // 用户
                    newCollData.push($scope.isNull(val.collection) ? 0 : val.collection);   // 收藏
                    newUserData.push($scope.isNull(val.complete) ? 0 : val.complete); // 完成
                });
                option = {
                    backgroundColor: '#394056',
                    title: {
                        text: '课程观看人数统计（30天以内）',
                        textStyle: {
                            fontWeight: 'normal',
                            fontSize: 16,
                            color: '#F1F1F3'
                        },
                        left: '6%'
                    },
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            lineStyle: {
                                color: '#57617B'
                            }
                        }
                    },
                    legend: {
                        icon: 'rect',
                        itemWidth: 14,
                        itemHeight: 5,
                        itemGap: 13,
                        //data: ['用户数量','收藏量','完成人数'], //, '桂林-企业', '南宁-企业'
                        right: '4%',
                        //                        textStyle: {
                        //                            fontSize: 12,
                        //                            color: '#F1F1F3'
                        //                        }
                        data: [{
                            name: '用户数量',
                            textStyle: {
                                fontSize: 12,
                                color: '#F1F1F3'
                            }
                        }, {
                            name: '收藏量',
                            textStyle: {
                                fontSize: 12,
                                color: '#F1F1F3'
                            }
                        }, {
                            name: '完成人数',
                            textStyle: {
                                fontSize: 12,
                                color: '#F1F1F3'
                            }
                        }]
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis: [{
                        type: 'category',
                        boundaryGap: false,
                        axisLine: {
                            lineStyle: {
                                color: '#57617B'
                            }
                        },
                        data: newName//['1月', '2月', '10月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'] //
                    }],
                    yAxis: [{
                        type: 'value',
                        axisTick: {
                            show: false
                        },
                        axisLine: {
                            lineStyle: {
                                color: '#57617B'
                            }
                        },
                        axisLabel: {
                            margin: 10,
                            textStyle: {
                                fontSize: 14
                            }
                        },
                        splitLine: {
                            lineStyle: {
                                color: '#57617B'
                            }
                        }
                    }],
                    series: [{
                        name: '用户数量',
                        type: 'line',
                        smooth: true,
                        lineStyle: {
                            normal: {
                                width: 1
                            }
                        },
                        areaStyle: {
                            normal: {
                                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                    offset: 0,
                                    color: 'rgba(137, 189, 27, 0.3)'
                                }, {
                                    offset: 0.8,
                                    color: 'rgba(137, 189, 27, 0)'
                                }], false),
                                shadowColor: 'rgba(0, 0, 0, 0.1)',
                                shadowBlur: 10
                            }
                        },
                        itemStyle: {
                            normal: {
                                color: 'rgb(137,189,27)'
                            }
                        },
                        data: newData//[196, 196, 197, 195, 0, 194, 189, 194, 280, 162, 75, 294]
                    }, {
                        name: '收藏量',
                        type: 'line',
                        smooth: true,
                        lineStyle: {
                            normal: {
                                width: 1
                            }
                        },
                        areaStyle: {
                            normal: {
                                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                    offset: 0,
                                    color: 'rgba(137, 189, 27, 0.3)'
                                }, {
                                    offset: 0.8,
                                    color: 'rgba(137, 189, 27, 0)'
                                }], false),
                                shadowColor: 'rgba(0, 0, 0, 0.1)',
                                shadowBlur: 10
                            }
                        },
                        itemStyle: {
                            normal: {
                                color: 'rgb(255,140,0)'
                            }
                        },
                        data: newCollData//[196, 196, 197, 195, 0, 194, 189, 194, 280, 162, 75, 294]
                    }, {
                        name: '完成人数',
                        type: 'line',
                        smooth: true,
                        lineStyle: {
                            normal: {
                                width: 1
                            }
                        },
                        areaStyle: {
                            normal: {
                                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                    offset: 0,
                                    color: 'rgba(137, 189, 27, 0.3)'
                                }, {
                                    offset: 0.8,
                                    color: 'rgba(137, 189, 27, 0)'
                                }], false),
                                shadowColor: 'rgba(0, 0, 0, 0.1)',
                                shadowBlur: 10
                            }
                        },
                        itemStyle: {
                            normal: {
                                color: 'rgb(220,20,60)'
                            }
                        },
                        data: newUserData //[190, 180, 123, 195, 0, 194, 189, 194, 280, 162, 75, 294]
                    }]
                };

                if (option && typeof option === "object") {
                    myChart.setOption(option, true);
                }
            } else {   // 获取失败 
                Msg.error("获取失败4！")
            }
        }, function errorCallback() {
            console.log("请求异常！");
        });
    }
    //课程章节列表
    $scope.chapterList = function () {
        RTS.chapterList({ courseid: $scope.courseid }).then(function (data) {
            debugger;
            if (data.errorcode == "0") {// 成功 
                $scope.detailedJSON = eval("(" + data.datas[0].detailed_JSON + ")");
                if ($scope.detailedJSON != undefined && $scope.detailedJSON.length > 0) {
                    for (var i = 0; i < $scope.detailedJSON.length; i++) {
                        $scope.detailedJSON[i].content = eval($scope.detailedJSON[i].content);

                        for (var a = 0; a < $scope.detailedJSON[i].content.length; a++) {

                            if ($scope.detailedJSON[i].content[a].chapterJson != undefined) {
                                $scope.detailedJSON[i].content[a].chapterJson = eval($scope.detailedJSON[i].content[a].chapterJson);
                            }
                            //$scope.detailedJSON[i].content[a] = $scope.chapterQuantity($scope.detailedJSON[i].content[a]);
                        }
                    }
                } else {
                    if ($scope.detailedJSON != undefined) {
                        $scope.detailedJSON = [$scope.detailedJSON];
                        /*
                        for (var a = 0; a < $scope.detailedJSON[0].content.length; a++) {
                        $scope.detailedJSON[0].content[a] = $scope.chapterQuantity($scope.detailedJSON[0].content[a]);
                        }
                        */
                    }
                }
            } else {
                console.log("课程章节列表请求异常！" + data.errorcode);
            }
        });
    }

    //    查询每个章节结果数量
    //    cstype:    章节类型(1.视频 2.文档 3.考试(测试)id 5.题库 4.线下 6.直播)
    $scope.chapterQuantity = function (chitem) {
        RTS.chapterQuantity({ csid: chitem.CSID, cstype: chitem.CSTYPE, orgid: sysUserInfo.getuserinfo().organization_ID }).then(function (datashare) {
            chitem.aaa = "888";
            return chitem;
        });
    }

    //章节内容收起和隐藏
    $scope.shouqi = function (chinfo) {
        if (chinfo.shouqi) {
            chinfo.shouqi = false;
        } else {
            chinfo.shouqi = true;
        }
    }

    //$scope.courseid    "76e18612-77ec-4d3d-a69b-5d95c1b13fa8"
    $scope.plparam = { "courseid": $scope.courseid, "organizationID": sysUserInfo.getuserinfo().orgStr, "userGroupID": sysUserInfo.getuserinfo().groupStr, "userRoleID": sysUserInfo.getuserinfo().roleStr, "pageIndex": 1, "pageSize": 12 };

    //分页
    $scope.paginationConf = {
        currentPage: 1, //$location.search().currentPage ? $location.search().currentPage :
        totalItems: 0,
        itemsPerPage: 12,
        //pagesLength: 10,
        perPageOptions: [12],
        //rememberPerPage: 'perPageItems',
        onChange: function () {

            if ((parseInt($scope.plparam.pageIndex) != parseInt($scope.paginationConf.currentPage)) || (parseInt($scope.plparam.pageSize) != parseInt($scope.paginationConf.itemsPerPage))) {
                if ($scope.paginationConf.currentPage == 0) { $scope.paginationConf.currentPage = 1; }
                //if ($scope.index1 % 2 == 1) {
                $scope.plparam.pageIndex = $scope.paginationConf.currentPage;
                $scope.plparam.pageSize = $scope.paginationConf.itemsPerPage;
                if ($scope.chapterJson.CSTYPE == 3) {
                    $scope.crparam.pageIndex = $scope.paginationConf.currentPage;
                    $scope.crparam.pageSize = $scope.paginationConf.itemsPerPage;
                    $scope.paperStatistics($scope.crparam.paperid);
                } else if ($scope.chapterJson.CSTYPE == 4) {
                    $scope.lsparam.pageIndex = $scope.paginationConf.currentPage;
                    $scope.lsparam.pageSize = $scope.paginationConf.itemsPerPage;
                    $scope.lineStatistics($scope.lsparam.csid);
                } else if ($scope.chapterJson.CSTYPE == 1 || $scope.chapterJson.CSTYPE == 2 || $scope.chapterJson.CSTYPE == 8) {
                    $scope.vsparam.pageIndex = $scope.paginationConf.currentPage;
                    $scope.vsparam.pageSize = $scope.paginationConf.itemsPerPage;
                    $scope.videoStatistics($scope.vsparam.csid);
                }
            }
        }
    }

    //查询人员学习记录
    $scope.peopleLearn = function () {
        RTS.peopleLearn($scope.plparam).then(function (datashare) {
            if (datashare.errorcode == "0") {// 成功 
                if(datashare.datas!=undefined&&datashare.datas!=null&&datashare.datas.length>0){
                    for(var a=0;a<datashare.datas.length;a++){
                        datashare.datas[a].eDate=datashare.datas[a].date_time;
                    }
                }
                if ($scope.plparam.pageIndex == 1) {
                    $scope.ppLearn = datashare.datas;
                } else {
                    $scope.ppLearn = $scope.ppLearn.concat(datashare.datas);
                }
                $scope.numCount = datashare.numCount;
            } else {
                console.log("课程学习记录请求异常！" + datashare.errorcode);
            }
        });
    }

    //查询所有人员学习记录(分页)
    $scope.allppLearn = function () {
        $scope.plparam.pageIndex = $scope.plparam.pageIndex + 1;
        $scope.peopleLearn();
    }

    $scope.statisbool = { "exam": false, "offlinetrain": false, "multifile": false };
    $scope.statissel = { "selexam": "0", "seloffline": "1" };

    //关闭记录页面
    $scope.hidestatis = function (chtype) {
        if (chtype == 3) {
            $scope.statisbool.exam = false;
        } else if (chtype == 4) {
            $scope.statisbool.offlinetrain = false;
        } else if (chtype == 1 || chtype == 2 || chtype == 8) {
            $scope.statisbool.multifile = false;
        }
    }

    //查看详细学习记录
    $scope.train_info = function (chitem) {
        $scope.chapterJson = chitem;
        if (chitem.CSTYPE == 3) {
            $scope.statisbool.exam = true;
            $scope.chapterJson = chitem.chapterJson[0];
            $scope.crparam.fraction = chitem.chapterJson[0].passGrade;
            $scope.paperStatistics($scope.chapterJson.paperId);
        } else if (chitem.CSTYPE == 4) {
            $scope.statisbool.offlinetrain = true;
            $scope.lineStatistics(chitem.CSID);
        } else if (chitem.CSTYPE == 1 || chitem.CSTYPE == 2 || chitem.CSTYPE == 8) {
            $scope.statisbool.multifile = true;
            $scope.videoStatistics(chitem.CSID);
        }
    }

    /**start*****考试详细信息**********/

    //考试
    $scope.checkexam = function (val) {
        $scope.crparam.pageIndex = 1
        $scope.statissel.selexam = val;
        if (val == 0) {
            $scope.crparam.type = "";
            $scope.crparam.single = 1;
        } else if (val == 1) {
            $scope.crparam.type = "1";
            $scope.crparam.single = 1;
        } else if (val == 2) {
            $scope.crparam.type = "2";
            $scope.crparam.single = 1;
            //查询单人最高成绩
        } else if (val == 3) {
            $scope.crparam.type = "3";
            $scope.crparam.single = 2;
        }
        $scope.paperStatistics($scope.crparam.paperid);
    }

    //线下学习
    $scope.checkoffline = function (val) {
        $scope.lsparam.pageIndex = 1
        $scope.statissel.seloffline = val;
        if (val == 1) {
            $scope.lsparam.type = "1";
        } else if (val == 2) {
            $scope.lsparam.type = "2";
        } else if (val == 3) {
            $scope.lsparam.type = "3";
        }
        $scope.lineStatistics($scope.lsparam.csid);
    }

    //文档、视频、图文学习
    $scope.checkvideo = function (val) {
        $scope.vsparam.pageIndex = 1
        $scope.vsparam.type = val;

        $scope.videoStatistics($scope.vsparam.csid);

    }

    $scope.crparam = { "paperid": "", "type": "", "fraction": "", "organizationID": sysUserInfo.getuserinfo().orgStr, "userGroupID": sysUserInfo.getuserinfo().groupStr, "userRoleID": sysUserInfo.getuserinfo().roleStr, "pageIndex": 1, "pageSize": 12, "orderby": "desc" };
    $scope.url = "";

    //type:是否合格,1合格 2.不合格
    //考试信息统计
    $scope.paperStatistics = function (paperid) {
        $scope.isloading = true;
        $scope.crparam.paperid = paperid;
        $scope.crparam.export = 1;
        $scope.crparam.sort = 1;
        $scope.crparam.organizationID = $scope.ParentData.userOrgValues.join(",");
        $scope.crparam.userGroupID = $scope.ParentData.userGroupValues.join(",");
        $scope.crparam.userRoleID = $scope.ParentData.userRightValues.join(",");

        $scope.url = $rootScope.userurl + "/course/paperStatistics?paperid=" + $scope.crparam.paperid + "&type=" + $scope.crparam.type + "&fraction=" + $scope.crparam.fraction + "&orderby=" + $scope.crparam.orderby + "&organizationID=" + $scope.crparam.organizationID + "&userGroupID=" + $scope.crparam.userGroupID + "&userRoleID=" + $scope.crparam.userRoleID + "&export=2&sort=" + $scope.crparam.sort;
        RTS.paperStatistics($scope.crparam).then(function (datashare) {
            $scope.isloading = false;
            if (datashare.errorcode == "0") {// 成功 
                $scope.PersList.examlist = datashare;
                $scope.paginationConf.currentPage = datashare.pageIndex;
                $scope.paginationConf.totalItems = datashare.numCount;
                //$scope.paginationConf.currentPage = 1;
            } else {
                console.log("考试信息统计异常！" + datashare.errorcode);
            }
        });
    }

    /**end*****考试详细信息**********/



    $scope.lsparam = { "csid": "", "type": "1", "organizationID": sysUserInfo.getuserinfo().orgStr, "userGroupID": sysUserInfo.getuserinfo().groupStr, "userRoleID": sysUserInfo.getuserinfo().roleStr, "pageIndex": 1, "pageSize": 12, "orderby": "desc" };
    //    type：    1.已报名 2.已到场 3.未到场    
    //    线下信息统计
    $scope.lineStatistics = function (csid) {
        $scope.isloading = true;
        $scope.lsparam.csid = csid;

        $scope.lsparam.organizationID = $scope.ParentData.userOrgValues.join(",");
        $scope.lsparam.userGroupID = $scope.ParentData.userGroupValues.join(",");
        $scope.lsparam.userRoleID = $scope.ParentData.userRightValues.join(",");

        RTS.lineStatistics($scope.lsparam).then(function (datashare) {
            $scope.isloading = false;
            if (datashare.errorcode == "0") {// 成功 
                $scope.PersList.offlinelist = datashare.datas;
                $scope.paginationConf.currentPage = datashare.pageIndex;
                $scope.paginationConf.totalItems = datashare.numCount;
            } else {
                console.log("线下信息统计异常！" + datashare.errorcode);
            }
        });
    }

    $scope.vsparam = { "csid": "", "type": "0", "time": $scope.chapterJson.CSTIME, "organizationID": sysUserInfo.getuserinfo().orgStr, "userGroupID": sysUserInfo.getuserinfo().groupStr, "userRoleID": sysUserInfo.getuserinfo().roleStr, "pageIndex": 1, "pageSize": 12, "orderby": "desc" };
    //    type:1.合格 2.未合格
    //    视频、文档、图文信息统计
    $scope.videoStatistics = function (csid) {
        $scope.isloading = true;
        $scope.vsparam.csid = csid;
        $scope.vsparam.time = $scope.chapterJson.CSTIME;
        $scope.vsparam.organizationID = $scope.ParentData.userOrgValues.join(",");
        $scope.vsparam.userGroupID = $scope.ParentData.userGroupValues.join(",");
        $scope.vsparam.userRoleID = $scope.ParentData.userRightValues.join(",");

        RTS.videoStatistics($scope.vsparam).then(function (datashare) {
            $scope.isloading = false;
            if (datashare.errorcode == "0") {// 成功 
                $scope.PersList.multifilelist = datashare.datas;
                $scope.paginationConf.currentPage = datashare.pageIndex;
                $scope.paginationConf.totalItems = datashare.numCount;
            } else {
                console.log("视频、文档、图文信息统计异常！" + datashare.errorcode);
            }
        });
    }

    //获取当前时间（天数）
    $scope.getdate = function (days) {
        var myDate = new Date(); //获取系统当前时间
        if (days != "") {
            myDate.setDate(myDate.getDate() + days);
        }
        var year = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
        var month = myDate.getMonth() + 1; //获取当前月份(0-11,0代表1月)
        var date = myDate.getDate(); //获取当前日(1-31)
        return year + "-" + (month < 10 ? "0" + month : month) + "-" + (date < 10 ? "0" + date : date);
    }


    // 选择器初始化
    $scope.ParentData = {
        ApiOpen: false,
        menu: [{ "id": "Org" }, { "id": "Role" }, { "id": "Group"}],
        userOrgList: [],
        userGroupList: [],
        userRoleList: [],
        userAuthorityList: [],
        userOrgValues: [],
        userGroupValues: [],
        userRightValues: [],
        style: ""
    }

    $scope.AddpersonFun = function (event) {
        $scope.ParentData.ApiOpen = true;
        $scope.ParentData.userOrgList = [];
        $scope.ParentData.userGroupList = [];
        $scope.ParentData.userRoleList = [];
        $scope.ParentData.userOrgValues = [];
        $scope.ParentData.userGroupValues = [];
        $scope.ParentData.userRightValues = [];
    }

    //页面监听组织结构、角色、用户组
    $scope.watch = function () {
        $scope.$watch('ParentData.ApiOpen', function (newValue, oldValue, scope) {
            if (!newValue) {
                $scope.ParentData.userOrgValues = [];
                $scope.ParentData.userGroupValues = [];
                $scope.ParentData.userRightValues = [];

                $scope.ParentData.userOrgList.forEach(function (val, index, arr) {
                    $scope.ParentData.userOrgValues.push(val.organization_ID);
                });

                $scope.ParentData.userGroupList.forEach(function (val, index, arr) {
                    $scope.ParentData.userGroupValues.push(val.userGroup_ID);
                });

                $scope.ParentData.userRoleList.forEach(function (val, index, arr) {
                    $scope.ParentData.userRightValues.push(val.roles_ID);
                });
                $scope.train_info($scope.chapterJson);
            }
        }, true);
    }

    /**********************/
    //批量添加人员 选择器初始化
    $scope.PeopleUserData = {
        ApiOpen: false,
        style: "",
        menu: [{ "id": "User"}],
        UserList: [],
        ViceuserOrgList: [],
        ViceuserRoleList: [],
        ViceuserGroupList: [],
        searchType: [],
        DB: "0"

    }
    //点击打开人员选择器事件
    $scope.selectStu = function (event) {
        $scope.PeopleUserData.UserList=[];
        $scope.PeopleUserData.DB="0";
        $scope.PeopleUserData.ApiOpen = true;
        $scope.PeopleUserData.event =event;
        $scope.PeopleUserData.style = $scope.mousePosition(event);
        $scope.WatchUserList();
    }
    $scope.selectLearn =[];
    //监听人员列表事件
    $scope.WatchUserList = function () {
        var watch = $scope.$watch('PeopleUserData.ApiOpen', function (newValue, oldValue, scope) {
        //判断 新数据源比旧数据源长度大的情况下 新增了用户
        if (!newValue) { //关闭事件
            $scope.selectLearn = $scope.selectLearn.concat($scope.PeopleUserData.UserList);
            //去重
            for(var a=0;a<$scope.selectLearn.length;a++){
                for(var b=a+1;b<$scope.selectLearn.length;b++){
                    if($scope.selectLearn[a].user_ID==$scope.selectLearn[b].user_ID){
                        $scope.selectLearn.splice(b,1);
                        b--;
                    }
                }
            }
        }
        }, true);
    }
    $scope.del_study=function(index){
        $scope.selectLearn.splice(index,1);
    }
     $scope.mousePosition = function (ev) {

        if (!ev) { ev = window.event; }
        if (ev.type != "click") {
            return;
        }
        var width = 0;
        var height = 0;
        if (ev.pageX || ev.pageY) {//firefox、chrome等浏览器
            if (document.documentElement.clientWidth - ev.pageX < 450) {
                width = ev.pageX - (450 - (document.documentElement.clientWidth - ev.pageX)) - 20;
            } else {
                width = ev.pageX;
            }
            if (document.documentElement.clientHeight - ev.pageY < 480) {
                height = ev.pageY - (480 - (document.documentElement.clientHeight - ev.pageY)) - 20;
            } else {
                height = ev.pageY;
            }

            return { "left": width + "px", "top": height + "px", "position": "fixed" };
        }

        return {// IE浏览器
            "left": ev.clientX + document.body.scrollLeft - document.body.clientLeft,
            "top": ev.clientY + document.body.scrollTop - document.body.clientTop
        };
    }
    $scope.studyloading=false;
    //展示按钮
    $scope.showCount=false;
    $scope.sumCount=0;
    $scope.clickCount=function(){
        $scope.sumCount+=1;
        if($scope.sumCount>=5){
            $scope.showCount=true;
        }
    }

    //保存
    $scope.SaveStuStudy=function(){
        
        if($scope.studyloading){
            return;
        }
        $scope.studyloading=true;
        var list=[];
        if($scope.selectLearn.length<=0){
            return;
        }
        $scope.selectLearn.forEach(function(data,index){
            list.push(data.user_ID);
        });
        RTS.addCourseRecord({uid:sysUserInfo.getuserinfo().user_ID,cid:$scope.traininfo.course_Id,uids:list.join(",")}).then(function (datashare) {
            $scope.studyloading = false;
            if (datashare.errorcode == "0") {// 成功 
                Msg.success("保存成功！");
            } else {
                Msg.error("保存失败！");
            }
        },function(e){
            $scope.studyloading = false;
        });
    }
    /*******编辑、保存********/
    $scope.Edit = function () {
        $scope.closeuser();
        updateUrl.upUrl(1);
        $state.go("index.Train.course.lukecheng", { courid: $scope.courseid });
    }
    //预览
    $scope.yulan = function (traininfo) {
        window.location = +"/resources/template/" + $scope.course_Id + ".html";
    }

    $scope.courseRelevant();
    $scope.courseStatistics();
    $scope.courseStatistics();
    $scope.peopleLearn();
    $scope.chapterList();
    $scope.watch();
    /***** 查询个人学习记录******/
    //请求参数
    $scope.peopleParams = {
        courseId: "", // 课程id
        stuId: "",  // 查看的学员id 
        userId: sysUserInfo.getuserinfo().user_ID,  //当前操作人
        startDate: "",   // 开始时间
        endDate: "", //结束时间
        pageIndex: 1,   //当前页
        pageSize: 10 // 每页数量
    }
    // 人员记录集合
    $scope.peopleRecoreList = [];
    // 人员详细记录总条数
    $scope.peopleRecoreListCount = 0;
    $scope.peopleRecoreObj = "";
    // 人员详细记录的显示隐藏
    $scope.peopleRecoreShow = false;
    // loading
    $scope.peopleRecoreLoading = false;
    // 打开人员详细记录的弹框
    $scope.openPeopleRecord = function (userObj) {
        $scope.peopleRecoreObj = userObj;
        $scope.peopleParams.courseId = userObj.course_id;
        $scope.peopleParams.arrangeId = userObj.arrange_id;
        $scope.peopleParams.stuId = userObj.userinfo.user_ID;
        $scope.peopleParams.pageIndex = 1;
        $scope.peopleParams.startDate = "";
        $scope.peopleParams.endDate = "";
        $scope.peopleRecoreShow = true;
        $scope.peopleRecoreList = [];
        $scope.getPeopleRecoreList();
    }
    // 获取学员记录信息
    $scope.getPeopleRecoreList = function () {
        $scope.peopleRecoreLoading = true;
        RTS.findSectionByCidUid($scope.peopleParams).then(function (response) {
            $scope.peopleRecoreLoading = false;
            if (response.errorcode == "0") {
                angular.forEach(response.datas, function (data, index) {
                    $scope.peopleRecoreList.push(data);
                });
                $scope.peopleRecoreListCount = response.numCount;
            } else {
                Msg.error("获取信息异常");
            }
        });
    }
    // 条件查询
    $scope.selWhereRecoreList = function (flag) {
        if (flag) {
            $scope.peopleParams.startDate = "";
            $scope.peopleParams.endDate = "";
        }
        $scope.peopleParams.pageIndex = 1;
        $scope.peopleRecoreList = [];
        $scope.getPeopleRecoreList();
    }
    // 查询所有
    $scope.nextRecoreList = function () {
        $scope.peopleParams.pageIndex += 1;
        $scope.getPeopleRecoreList();
    }
    // 关闭统计记录
    $scope.closeRecoreList = function () {
        $scope.peopleRecoreShow = false;
    }
    // 获取时间
    $scope.getRecoreTime = function () {
        $scope.peopleParams.startDate = document.getElementById("startTime").value;
        $scope.peopleParams.endDate = document.getElementById("endTime").value;
    }

} ]); 